package pl.koszolko.documentclustering.ui.dendrogram;


import pl.koszolko.documentclustering.cluster.Dendrogram;

public class Node {
	private Dendrogram.Node node;
	private Node parent;
	private double x;
	private double y;
	private Node childL;
	private Node childR;
	
	
	public Node(pl.koszolko.documentclustering.cluster.Dendrogram.Node node,
			double x, double y) {
		super();
		this.node = node;
		this.x = x;
		this.y = y;
	}
	
	public Dendrogram.Node getNode() {
		return node;
	}
	public void setNode(Dendrogram.Node node) {
		this.node = node;
	}
	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	public Dendrogram.Node getParentDendrogramNode() {
		if(node != null) {
			return node.getParent();
		} 
		return null;
	}

	public Node getChildL() {
		return childL;
	}

	public void setChildL(Node childL) {
		this.childL = childL;
	}

	public Node getChildR() {
		return childR;
	}

	public void setChildR(Node childR) {
		this.childR = childR;
	}

	public Node getParent() {
		return parent;
	}

	public void setParent(Node parent) {
		this.parent = parent;
	}

	public String getDocumentTitle() {
		return node.getFirstDocumentTitle();
	}
	
	public Double getSimilarity() {
		if(node != null) {
			return node.getSimilarity();
		}
		return 0.0;
	}

	public int getClusterNumber() {
		return node.getNr();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((node == null) ? 0 : node.hashCode());
		long temp;
		temp = Double.doubleToLongBits(x);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(y);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Node other = (Node) obj;
		if (node == null) {
			if (other.node != null)
				return false;
		} else if (!node.equals(other.node))
			return false;
		if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
			return false;
		if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
			return false;
		return true;
	}
}
